package com.horsecoder.im;

import cc.eamon.open.flow.spring.scanner.FlowScan;
import com.horsecoder.im.common.NettyServer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableFeignClients(basePackages = {})
@EnableDiscoveryClient
@EnableCaching
@ServletComponentScan("com.horsecoder.im")
@EnableTransactionManagement
@MapperScan(value = {
        "com.horsecoder.im.*.datainterface"
})
@EnableSwagger2
@FlowScan(flowPackages = {"com.horsecoder.im.flow"})
public class AppStarter {

    private static Integer port = 21313;

    @Value("${com.horsecoder.im.server.port}")
    public void setPort(Integer port) {
        AppStarter.port = port;
    }

    public static void main(String[] args) {
        nettyMain();
        SpringApplication.run(AppStarter.class, args);
    }

    public static void nettyMain() {
        try {
            new NettyServer(port).run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}